<template>
    <view class="feedback">
        <view class="fk">
            <text style="font-weight: bold">反馈内容：</text>
        </view>
        <view class="neirong">
            <textarea class="mytest" style="width: 100%" @input="inputChangeMytest"></textarea>
        </view>

        <button class="bnt" type="primary" @tap="startUploadImg">提交反馈</button>
    </view>
</template>

<script>
const app = getApp();
var urlPrefix = app.globalData.urlPrefix;
export default {
    data() {
        return {
            mytest: '',
			token:null
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
		let token = uni.getStorageSync("token");
		this.token = token
	},
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    onShareTimeline(res) {
        // 分享到朋友圈
        return {};
    },
    methods: {
        inputChangeMytest(e) {
            let that = this;
            that.setData({
                mytest: e.detail.value
            });
        },

        startUploadImg: function () {
            var userId = uni.getStorageSync('userId');
            var mytest = this.mytest.replace(/\s+/g, '');
            if (mytest == null || mytest == '') {
                uni.showToast({
                    title: '反馈内容不能为空！',
                    icon: 'none',
                    duration: 2000
                });
                return;
            }
            uni.request({
                url: urlPrefix + '/api/applet/myInfo/addFeedBack',
                method: 'POST',
                data: {
                    userId: userId,
                    content: mytest
                },
                header: {
                    'content-type': 'application/json',
                    "token": this.token
                },
                success: function (res) {
                    if (res.data.resp_code == 0) {
                        uni.showToast({
                            title: '提交成功',
                            icon: 'success',
                            duration: 2000,
                            success: function () {
                                setTimeout(function () {
                                    uni.switchTab({
                                        url: '/pages/myinfo/myinfo'
                                    });
                                }, 1000);
                            }
                        });
                    } else {
                        uni.showToast({
                            title: '提交过于频繁',
                            icon: 'none',
                            duration: 2000
                        });
                    }
                }
            });
        }
    }
};
</script>
<style lang="scss">
@import './feedback.scss';
</style>
